<template>
	<view class="">
		<cu-custom :showBack="false" />
		<scroll-view scroll-y="true" :style="'height:'+scorllHeight+ 'px;'" 
			show-scrollbar="false">
			<view class="p-3 bgcolor">
				<indexDashbord :FirstDashbord="indexData" />
			</view>
			<dataInfo :startDate="startDate" :dataInfo="dataInfo" @changeData="handlerChangeDate"/>
			<orderCom :title="'订单信息'" :index="0" :orderObject="orderObject" />
			<orderCom :title="'商品信息'" :index="1" :orderObject="shopObject" />
			<orderCom :title="'待处理信息'" :index="2" :orderObject="pendingObject" />
			<!-- <view class="priceTrendChart-box mb-2">
				<view class="pl-3 pr-3 mt-2 mb-2 title">近30天河蟹价格走势图</view>
				<priceTrendChart />
			</view> -->
		</scroll-view>
	</view>
</template>

<script>
	import indexDashbord from "@/components/index/dashbord.vue"
	import dataInfo from "@/components/index/dataInfo.vue"
	import orderCom from "@/components/index/order.vue"
	import title from "@/components/common/title.vue"
	import priceTrendChart from "@/components/priceTrendChart/index.vue"
	import cuCustom from '@/components/common/custom.vue'
	import interceptor from "@/utils/request.js"
	export default {
		components: {
			indexDashbord,
			dataInfo,
			orderCom,
			title,
			priceTrendChart,
			cuCustom
		},
		data() {
			return {
				triggered: false,
				_freshing: false,
				scorllHeight: 500,
				orderObject: {
					orderTitle: "订单总数量",
					orderValue: 300,
					list: [{
							title: "待发货订单",
							value: 200
						},
						{
							title: "待支付订单",
							value: 200
						},
						{
							title: "待确认订单",
							value: 200
						},
						{
							title: "部分发货订单",
							value: 200
						},
						{
							title: "退款申请",
							value: 200
						},
						{
							title: "退货申请",
							value: 200
						},
						{
							title: "新缺货登记",
							value: 200
						},
						{
							title: "已成交订单数",
							value: 200
						},

					]
				},
				shopObject: {
					orderTitle: "商品",
					orderValue: 10,
					list: [{
							title: "审核通过商品数",
							value: 200
						},
						{
							title: "审核未通过商品数",
							value: 200
						},
						{
							title: "库存警告商品数",
							value: 200
						},
						{
							title: "新品推荐数",
							value: 200
						},
						{
							title: "精品推荐数",
							value: 200
						},
						{
							title: "热销商品数",
							value: 200
						},
						{
							title: "促销商品数",
							value: 200
						},
						{
							title: "已下架商品总数",
							value: 200
						},

					]
				},
				pendingObject: {
					orderTitle: "待处理",
					orderValue: 10,
					list: [{
							title: "待审核商品",
							value: 2
						},
						{
							title: "未处理佣金",
							value: 200
						}
					]
				},
				indexData: null,
				dataInfo:null,
				startDate:""
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res => {
					this.scorllHeight = res.windowHeight - uni.upx2px(180)
				})
			})
			this._freshing = false;  
		},
		onShow() {
			this.getHomeInfo()
		},
		methods: {
			refresherrefresh() {
				if (this._freshing) return;
				this._freshing = true;
				if (!this.triggered) //界面下拉触发，triggered可能不是true，要设为true  
					this.triggered = true;
				setTimeout(() => {
					this.triggered = false; //触发onRestore，并关闭刷新图标  
					this._freshing = false;
					this.getHomeInfo()
				}, 1000)
			},
			getHomeInfo() {
				interceptor.get('/supplier_applet_api.php?act=homePage', {
					supplier_id: uni.getStorageSync("supplier_id")
				}).then((res) => {
					if (res.status === 1) {
						const {
							info
						} = res
						this.indexData = info.today
						this.indexData.new_await_ship = info.order.await_ship
						this.orderObject.orderValue = info.order.total
						this.orderObject.list[0].value = info.order.await_ship
						this.orderObject.list[1].value = info.order.await_pay
						this.orderObject.list[2].value = info.order.unconfirmed
						this.orderObject.list[3].value = info.order.shipped_part
						this.orderObject.list[4].value = info.order.new_repay
						this.orderObject.list[5].value = info.order.returns
						this.orderObject.list[6].value = info.order.booking_goods
						this.orderObject.list[7].value = info.order.finished
						this.shopObject.orderValue = info.goods.total
						this.shopObject.list[0].value = info.goods.pass
						this.shopObject.list[1].value = info.goods.impass
						this.shopObject.list[2].value = info.goods.warn
						this.shopObject.list[3].value = info.goods.new
						this.shopObject.list[4].value = info.goods.best
						this.shopObject.list[5].value = info.goods.hot
						this.shopObject.list[6].value = info.goods.promote
						this.shopObject.list[7].value = info.goods.deleted
						this.pendingObject.orderValue = info.task.total
						this.pendingObject.list[0].value = info.task.goods
						this.pendingObject.list[1].value = info.task.article
						this.getCurrentDate()

					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							success() {
								uni.reLaunch({
									url: '/pagesPackage/minePackage/login/login'
								});
							}
						});
					}
				})
			},
			getCurrentDate() {
				const today = new Date();
				const year = today.getFullYear();
				const month = today.getMonth() + 1; // 月份是从0开始的
				this.startDate = `${year}-${month.toString().padStart(2, '0')}`
				this.getDataInfo()
			},
			handlerChangeDate(value){
				console.log(value)
				this.startDate = value
				this.getDataInfo()
			},
			getDataInfo(){
				let params = {
					supplier_id: uni.getStorageSync("supplier_id"),
					ym: this.startDate
				}
				interceptor.get("/supplier_applet_api.php?act=selMonthList",params).then((res) =>{
					this.dataInfo = res.info.today
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	::v-deep .uni-input {
		height: 20px !important;
	}

	.bgcolor {
		background: linear-gradient(0deg, rgba(235, 236, 237, .3), #F4E3E2);
	}

	.priceTrendChart-box {
		.title {
			font-weight: 500;
			font-size: 34rpx;
			color: #181C25;
			line-height: 46rpx;
		}
	}
</style>